package com.cxhc.system.service.hcdoc.impl;

import java.util.List;

import com.cxhc.system.domain.hcdoc.HdProjectDocInfo;
import com.cxhc.system.domain.hcdoc.HdSmallBid;
import com.cxhc.system.mapper.hcdoc.HdProjectDocInfoMapper;
import com.cxhc.system.mapper.hcdoc.HdSmallBidMapper;
import com.cxhc.system.service.hcdoc.IHdSmallBidService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

/**
 * 小额招标信息Service业务层处理
 * 
 * @author Dhq
 * @date 2024-09-26
 */
@Service
public class HdSmallBidServiceImpl implements IHdSmallBidService
{
    @Autowired
    private HdSmallBidMapper hdSmallBidMapper;

    @Autowired
    private HdProjectDocInfoMapper hdProjectDocInfoMapper;

    /**
     * 查询小额招标信息
     * 
     * @param id 小额招标信息主键
     * @return 小额招标信息
     */
    @Override
    public HdSmallBid selectHdSmallBidById(Long id)
    {
        HdSmallBid hdSmallBid = hdSmallBidMapper.selectHdSmallBidById(id);
        List<HdProjectDocInfo> hdProjectDocInfos = hdProjectDocInfoMapper.selectListByProjectIdAndModule(String.valueOf(hdSmallBid.getId()) ,"5");
        hdSmallBid.setHdProjectDocInfos(hdProjectDocInfos);
        return hdSmallBid;
    }

    /**
     * 查询小额招标信息列表
     * 
     * @param hdSmallBid 小额招标信息
     * @return 小额招标信息
     */
    @Override
    public List<HdSmallBid> selectHdSmallBidList(HdSmallBid hdSmallBid)
    {
        return hdSmallBidMapper.selectHdSmallBidList(hdSmallBid);
    }

    /**
     * 新增小额招标信息
     * 
     * @param hdSmallBid 小额招标信息
     * @return 结果
     */
    @Override
    public int insertHdSmallBid(HdSmallBid hdSmallBid)
    {
        int insert = hdSmallBidMapper.insertHdSmallBid(hdSmallBid);

        if (1 == insert){
            List<HdProjectDocInfo> hdProjectDocInfos = hdSmallBid.getHdProjectDocInfos();
            if (!CollectionUtils.isEmpty(hdProjectDocInfos)){
                for (HdProjectDocInfo hdProjectDocInfo : hdProjectDocInfos) {
                    //文档所属模块1-项目中心 2-信访件 3-年度资料 4-停车包月 5-小额招标
                    hdProjectDocInfo.setModule("5");
                    hdProjectDocInfo.setProjectInfoId(String.valueOf(hdSmallBid.getId()));
                }
                hdProjectDocInfoMapper.batchInsertDoc(hdProjectDocInfos);
            }
        }
        return insert;
    }

    /**
     * 修改小额招标信息
     * 
     * @param hdSmallBid 小额招标信息
     * @return 结果
     */
    @Override
    public int updateHdSmallBid(HdSmallBid hdSmallBid)
    {
        return hdSmallBidMapper.updateHdSmallBid(hdSmallBid);
    }

    /**
     * 批量删除小额招标信息
     * 
     * @param ids 需要删除的小额招标信息主键
     * @return 结果
     */
    @Override
    public int deleteHdSmallBidByIds(Long[] ids)
    {
        return hdSmallBidMapper.deleteHdSmallBidByIds(ids);
    }

    /**
     * 删除小额招标信息信息
     * 
     * @param id 小额招标信息主键
     * @return 结果
     */
    @Override
    public int deleteHdSmallBidById(Long id)
    {
        return hdSmallBidMapper.deleteHdSmallBidById(id);
    }
}
